<?php
// +----------------------------------------------------------------------
// | PHP [ JUST YOU ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2017 http://www.jyphp.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: FlyingPig <flyingpigfp@163.com>
// +----------------------------------------------------------------------

namespace App\Http\Controllers;


use App\Common\Tool;
use App\Exceptions\ApiException;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Redis;

class RedisRoom extends Base
{
    /**
     * @api 俱乐部房间的Redis数据
     * @param room_key
     * @return array
     * @throws ApiException
     */
    public function clubRoom()
    {
        $room_id = Tool::getRedisRoomId($this->param['room_pwd']);
        if (empty($room_id)) {
            throw new ApiException('房间不存在:'.$room_id,6);
        }
        $object = DB::table('t_create_room_rec')->where('clubid','>',0)->where('id',$room_id)->first(['service_id','desk_id','id','clubid']);
        if (empty($object)) {
            throw new ApiException('房间信息不存在',6);
        }
        if (!DB::table('t_club_member_info')->where('clubid',$object->clubid)->where('uid',$this->uid)->value('uid')) {
            throw new ApiException('您不是该俱乐部成员,不能加入房间',6);
        }
        return $this->returnData([
            'room_id' => $object->desk_id,
            'server_id' => $object->service_id,
            'ticket_id' => $object->id
        ]);
    }


    /**
     * @api 普通房间的Redis数据
     * @param room_key
     * @return array
     * @throws ApiException
     */
    public function Room()
    {
        $room_id = Tool::getRedisRoomId($this->param['room_pwd']);
        if (empty($room_id)) {
            throw new ApiException('房间不存在:'.$room_id,6);
        }
        $object = DB::table('t_create_room_rec')->where('clubid',0)->where('id',$room_id)->first(['service_id','desk_id']);
        if (empty($object)) {
            throw new ApiException('房间信息不存在',6);
        }
        return $this->returnData([
            'room_id' => $object->desk_id,
            'server_id' => $object->service_id
        ]);
    }
}